﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SMS.Entities;
using SMS.DAL.DAHelpers;

namespace SMS.DAL
{
    public class SalesManDetailDA : BaseDA<SalesManDetail>
    {
        public override SalesManDetail SaveObject(string userName, SalesManDetail tObject)
        {

            throw new NotImplementedException();
        }

        public override bool DeleteObject(string userName, SalesManDetail tObject)
        {
            throw new NotImplementedException();
        }

        public override List<SalesManDetail> GetObjectList(string userName, DateTime fromDate, DateTime toDate)
        {
            throw new NotImplementedException();
        }

        public override List<SalesManDetail> SearchObject(string userName, string SearchText)
        {
            System.Data.IDataReader reader = null;
            try
            {
                dbHelper.AddParameter("@SearchText", SearchText);
                reader = dbHelper.ExecuteReader("USP_SEARCH_SALESMAN", System.Data.CommandType.StoredProcedure, System.Data.ConnectionState.Closed);
                List<SalesManDetail> results = new List<SalesManDetail>();
                while (reader.Read())
                    results.Add(GetSalesManDetailObject(reader));
                reader.Close();
                return results;
            }
            catch (Exception ex)
            {
                LogException(userName, ex, null);
                throw;
            }
        }

        private SalesManDetail GetSalesManDetailObject(System.Data.IDataReader reader)
        {
            int i = 0;
            SalesManDetail product = new SalesManDetail()
            {
                SalesMan_ID = reader.GetInt32(i++),
                SalesMan_Name = reader.GetString(i++),
                SalesMan_Mobile=reader.GetString(i++),
                SalesMan_Address=reader.GetString(i++),
                DateOfJoining = reader.GetDateTime(i++),
                DOB=reader.GetDateTime(i++),
                IsLive=reader.GetBoolean(i++)
                
            };
            return product;
        }
    }
}
